-- UCAgent
-- Created by chengb Jan/11/2016
-- UC九游平台代理

module("UCAgent", package.seeall);

-- 内部函数声明
local whenUserLevelUp;

function init()
    EventMgr.removeAll("UCAgent");

    -- 关注玩家升级的回调
    EventMgr.register("UCAgent", event.USER_LEVEL_UP, whenUserLevelUp);
end

-- 显示UC登录窗口
function showUCLogin()
    local isSwitch = "0";
    callJavaFunc("showUCLogin", {isSwitch}, "(Ljava/lang/String;)V");
end

-- 切换UC账号
function switchUCAccount()
    local isSwitch = "1";
    callJavaFunc("showUCLogin", {isSwitch}, "(Ljava/lang/String;)V");
end

----------------------
-- 购买商品
-- @param sku 商品库存标识
function buyPurchase(sku)
    local serverId = getCurrentServerId();
    local account  = getGaming3rdAccount();
    local platform = PUBLISH_TYPE_UC;

    callJavaFunc("buyPurchase", {sku, account, serverId, platform},
        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
end

-- 玩家升级的回调
function whenUserLevelUp(args)
    local level = args.level;
    local account = getGaming3rdAccount() or "";
    local rid = ME.user:getRid();
    local name = ME.user:getName();
    local serverId = getCurrentServerId();
    local firstLoginTime = ME.user.dbase:query("first_login_time") or TimeM.getServerTime();

    callJavaFuncWithClass("com.ChannelDelegate", "onUserLevelUp", {account, rid, name, tostring(serverId),
        tostring(level), tostring(firstLoginTime)},
        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");

end